package com.graduate.front.compont;

import com.graduate.common.entity.Users;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @author bwzfy
 * @create 2021/5/11
 **/
//@Component
public class MyHttpSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        System.out.println("session被初始化了一次");
        HttpSession session = httpSessionEvent.getSession();
        Users users = new Users();
        users.setId(1);
        users.setEmail("123@qq.com");
        users.setIdCard("122312312312321");
        users.setPhoneNum("10086");
        users.setUsername("admin");
        session.setAttribute("user", users);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {

    }
}
